package kayao.client.network.message;

import android.os.SystemClock;


public abstract class Message {
	public static final int PRIORITY_LOW = 0;
	public static final int PRIORITY_MEDIUM = 1;
	public static final int PRIORITY_HIGH = 2;
	
	protected static int sMessageIdCounter = 0;
	
	protected long mTimeout;
	protected String mTargetAddress;
	protected byte[] mSendData;
	protected int mMessageId;
	
	protected int mTimeoutLength;
	protected int mRetries;
	protected int mPriority;
	
	protected Message(String targetAddress, int retries, int timeoutLength, int priority) {
		mTargetAddress = targetAddress;
		mRetries = retries;
		mTimeoutLength = timeoutLength;
		mPriority = priority;
		
		mMessageId = sMessageIdCounter;
		sMessageIdCounter++;
	}

	public void messageSent() {
		long time=SystemClock.uptimeMillis();
		mTimeout = time + mTimeoutLength;
		mRetries--;
		
		System.out.println("[Message] \t Msg: " + mMessageId + " was sent in time: "+time + " and timeout: "+mTimeout);
	}
	
	public String getTargetAddress() {
		return mTargetAddress;
	}
	
	public byte[] getData(){
		return mSendData;
	}
	
	public int getMessageId() {
		return mMessageId;
	}
	
	public long getTimeout() {
		return mTimeout;
	}
	
	public int getRetriesLeft() {
		return mRetries;
	}
	
	public int getPriority() {
		return mPriority;
	}
	
	public abstract void createPacketData();
	public abstract String type();

	public void setTimeout(long timeout) {
		mTimeout=timeout;
		
	}
}